Developer Documentation

QuickTime 4 API Documentation

Inside Macintosh: Imaging with QuickDraw

Previous | Chapter Top | Chapter Contents | Next |

Data Structures

This section shows the Pascal data structures for the PixMap , CGrafPort , RGBColor , ColorSpec , ColorTable , MatchRec , PixPat , CQDProcs , and GrafVars records.

Analogous to the bitmap that basic QuickDraw uses to describe a bit image, a pixel map is used by Color QuickDraw to describe a pixel image. A pixel map, which is a data structure of type PixMap , contains information about the dimensions and contents of a pixel image, as well as information about the image's storage format, depth, resolution, and color usage.

As a basic graphics port (described in the chapter "Basic QuickDraw") defines the black-and-white and basic eight-color drawing environment for basic QuickDraw, a color graphics port defines the more sophisticated color drawing environment for Color QuickDraw. A color graphics port is defined by a data structure of type CGrafPort .

You usually specify a color to Color QuickDraw by creating an RGBColor record in which you assign the red, green, and blue values of the color. For example, when you want to set the foreground color for drawing, you create an RGBColor record that defines the foreground color you desire, then you pass that record as a parameter to the RGBForeColor procedure.

When creating a PixMap record for an indexed device, Color QuickDraw creates a ColorTable record that defines the best colors available for the pixel image on that graphics device. The Color Manager also stores a ColorTable record for the currently available colors in the graphics device's CLUT.

One of the fields in a ColorTable record requires a value of type cSpecArray , which is defined as an array of ColorSpec records. Typically, your application needs to create ColorTable records and ColorSpec records only if it uses the Palette Manager, as described in the chapter "Palette Manager" in Inside Macintosh: Advanced Color Imaging .

You can customize the SeedCFill and CalcCMask procedures by writing your own color search functions and pointing to them in the matchProc parameters for these procedures. When SeedCFill or CalcCMask calls your color search function, the GDRefCon field of the current GDevice record (described in the chapter "Graphics Devices") contains a pointer to a MatchRec record. This record contains the RGB value of the seed pixel or seed color for which your color search function should search.

Your application typically does not create PixPat records. Although you can create PixPat records in your program code, it is usually easier to create pixel patterns using the pixel pattern resource, which is described on The Pixel Pattern Resource .

You need to use the CQDProcs record only if you customize one or more of QuickDraw's low-level drawing routines.

Finally, the GrafVars record contains color information that supplements the information in the CGrafPort record, of which it is logically a part.

PixMap

A pixel map, which is defined by a data structure of type PixMap , contains information about the dimensions and contents of a pixel image, as well as information on the image's storage format, depth, resolution, and color usage.

TYPE    PixMap =
RECORD
    baseAddr:           Ptr;            {pixel image}
    rowBytes:           Integer;        {flags, and row width}
    bounds:             Rect;           {boundary rectangle}
    pmVersion:          Integer;        {PixMap record version number}
    packType:           Integer;        {packing format}
    packSize:           LongInt;        {size of data in packed state}
    hRes:               Fixed;          {horizontal resolution}
    vRes:               Fixed;          {vertical resolution}
    pixelType:          Integer;        {format of pixel image}
    pixelSize:          Integer;        {physical bits per pixel}
    cmpCount:           Integer;        {logical components per pixel}
    cmpSize:            Integer;        {logical bits per component}
    planeBytes:         LongInt;        {offset to next plane}
    pmTable:            CTabHandle;     {handle to the ColorTable record }
                                        { for this image}
    pmReserved:         LongInt;        {reserved for future expansion}
END;
baseAddr
For an onscreen pixel image, a pointer to the first byte of the image. For optimal performance, this should be a multiple of 4. The pixel image that appears on a screen is normally stored on a graphics card rather than in main memory.

The baseAddr field of the PixMap record for an offscreen graphics world contains a handle instead of a pointer. You must use the GetPixBaseAddr function (described in the chapter "Offscreen Graphics Worlds" in this book) to obtain a pointer to the PixMap record for an offscreen graphics world. Your application should never directly access the baseAddr field of the PixMap record for an offscreen graphics world; instead, your application should always use GetPixBaseAddr .

rowBytes
The offset in bytes from one row of the image to the next. The value must be even, less than $4000, and for best performance it should be a multiple of 4. The high 2 bits of rowBytes are used as flags. If bit 15 = 1, the data structure pointed to is a PixMap record; otherwise it is a BitMap record.
bounds
The boundary rectangle, which links the local coordinate system of a graphics port to QuickDraw's global coordinate system and defines the area of the bit image into which QuickDraw can draw. By default, the boundary rectangle is the entire main screen. Do not use the value of this field to determine the size of the screen; instead use the value of the gdRect field of the GDevice record for the screen, as described in the chapter "Graphics Devices" in this book.
pmVersion
The version number of Color QuickDraw that created this PixMap record. The value of pmVersion is normally 0. If pmVersion is 4, Color QuickDraw treats the PixMap record's baseAddr field as 32-bit clean. (All other flags are private.) Most applications never need to set this field.
packType
The packing algorithm used to compress image data. Color QuickDraw currently supports a packType of 0, which means no packing, and values of 1 to 4 for packing direct pixels.
packSize
The size of the packed image in bytes. When the packType field contains the value 0, this field is always set to 0.
hRes
The horizontal resolution of the pixel image in pixels per inch. This value is of type Fixed ; by default, the value here is $00480000 (for 72 pixels per inch).
vRes
The vertical resolution of the pixel image in pixels per inch. This value is of type Fixed ; by default, the value here is $00480000 (for 72 pixels per inch).
pixelType
The storage format for a pixel image. Indexed pixels are indicated by a value of 0. Direct pixels are specified by a value of RGBDirect , or 16. In the PixMap record of the GDevice record (described in the chapter "Graphics Devices") for a direct device, this field is set to the constant RGBDirect when the screen depth is set .
pixelSize
Pixel depth; that is, the number of bits used to represent a pixel. Indexed pixels can have sizes of 1, 2, 4, and 8 bits; direct pixel sizes are 16 and 32 bits.
cmpCount
The number of components used to represent a color for a pixel. With indexed pixels, each pixel is a single value representing an index in a color table, and therefore this field contains the value 1--the index is the single component. With direct pixels, each pixel contains three components--one integer each for the intensities of red, green, and blue--so this field contains the value 3.
cmpSize
The size in bits of each component for a pixel. Color QuickDraw expects that the sizes of all components are the same, and that the value of the cmpCount field multiplied by the value of the cmpSize field is less than or equal to the value in the pixelSize field.
For an indexed pixel value, which has only one component, the value of the cmpSize field is the same as the value of the pixelSize field--that is, 1, 2, 4, or 8.
For direct pixels there are two additional possibilities:
A 16-bit pixel, which has three components, has a cmpSize value of 5. This leaves an unused high-order bit, which Color QuickDraw sets to 0.
A 32-bit pixel, which has three components (red, green, and blue), has a cmpSize value of 8. This leaves an unused high-order byte, which Color QuickDraw sets to 0.
If presented with a 32-bit image--for example, in the CopyBits procedure--Color QuickDraw passes whatever bits are there, and it does not set the high byte to 0. Generally, therefore, your application should clear the memory for the image to 0 before creating a 16-bit or 32-bit image. The Memory Manager functions NewHandleClear and NewPtrClear , described in Inside Macintosh: Memory , assist you in allocating prezeroed memory.
planeBytes
The offset in bytes from one drawing plane to the next. This field is set to 0.
pmTable
A handle to a ColorTable record (described on ColorTable ) for the colors in this pixel map.
pmReserved
Reserved for future expansion. This field must be set to 0 for future compatibility.

Note that the pixel map for a window's color graphics port always consists of the pixel depth, color table, and boundary rectangle of the main screen, even if the window is created on or moved to an entirely different screen.

CGrafPort

A color graphics port, which is defined by a data structure of type CGrafPort , defines a complete drawing environment that determines where and how color graphics operations take place.

All graphics operations are performed in graphics ports. Before a color graphics port can be used, it must be allocated and initialized with the OpenCPort procedure, which is described on OpenCPort . Normally, you don't call OpenCPort yourself. In most cases your application draws into a color window you've created with the GetNewCWindow or NewCWindow function or draws into an offscreen graphics world created with the NewGWorld function. The two Window Manager functions (described in the chapter "Window Manager" in Inside Macintosh: Macintosh Toolbox Essentials ) and the NewGWorld function (described in the chapter "Offscreen Graphics Worlds" in this book) call OpenCPort to create the window's graphics port.

You can have many graphics ports open at once; each one has its own local coordinate system, pen pattern, background pattern, pen size and location, font and font style, and pixel map in which drawing takes place.

Several fields in this record define your application's drawing area. All drawing in a graphics port occurs in the intersection of the graphics port's boundary rectangle and its port rectangle. Within that intersection, all drawing is cropped to the graphics port's visible region and its clipping region.

The Window Manager and Dialog Manager routines GetNewWindow , GetNewDialog , Alert , StopAlert , NoteAlert , and CautionAlert (described in Inside Macintosh: Macintosh Toolbox Essentials ) create a color graphics port if color-aware resources (such as resource types 'wctb' , 'dctb' , or 'actb' ) are present.

The CGrafPort record is the same size as the GrafPort record, and most of its fields are identical. The structure of the CGrafPort record, is as follows:

TYPE CGrafPtr=^CGrafPort;
CGrafPort =
RECORD
    device:             Integer;            {device ID for font selection}
    portPixMap:         PixMapHandle;       {handle to PixMap record}
    portVersion:        Integer;            {highest 2 bits always set}
    grafVars:           Handle;             {handle to a GrafVars record}
    chExtra:            Integer;            {added width for nonspace characters}
    pnLocHFrac:         Integer;            {pen fraction}
    portRect:           Rect;               {port rectangle}
    visRgn:             RgnHandle;          {visible region}
    clipRgn:            RgnHandle;          {clipping region}
    bkPixPat:           PixPatHandle;       {background pattern}
    rgbFgColor:         RGBColor;           {requested foreground color}
    rgbBkColor:         RGBColor;           {requested background color}
    pnLoc:              Point;              {pen location}
    pnSize:             Point;              {pen size}
    pnMode:             Integer;            {pattern mode}
    pnPixPat:           PixPatHandle;       {pen pattern}
    fillPixPat:         PixPatHandle;       {fill pattern}
    pnVis:              Integer;            {pen visibility}
    txFont:             Integer;            {font number for text}
    txFace:             Style;              {text's font style}
    txMode:             Integer;            {source mode for text}
    txSize:             Integer;            {font size for text}
    spExtra:            Fixed;              {added width for space characters}
    fgColor:            LongInt;            {actual foreground color}
    bkColor:            LongInt;            {actual background color}
    colrBit:            Integer;            {plane being drawn}
    patStretch:         Integer;            {used internally}
    picSave:            Handle;             {picture being saved, used internally}
    rgnSave:            Handle;             {region being saved, used internally}
    polySave:           Handle;             {polygon being saved, used internally}
    grafProcs:          CQDProcsPtr;        {low-level drawing routines}
END;

You can read the fields of a CGrafPort record directly, but you should not store values directly into them. Use the QuickDraw routines described in this book to alter the fields of a graphics port.

device
Device-specific information that's used by the Font Manager to achieve the best possible results when drawing text in the graphics port. There may be physical differences in the same logical font for different output devices, to ensure the highest-quality printing on the device being used. For best results on the screen, the default value of the device field is 0.
portPixMap
A handle to a PixMap record (described on PixMap ), which describes the pixels in this color graphics port.
portVersion
In the highest 2 bits, flags set to indicate that this is a CGrafPort record and, in the remainder of the field, the version number of Color QuickDraw that created this record.
grafVars
A handle to the GrafVars record (described on GrafVars ), which contains additional graphics fields of color information.
chExtra
A fixed-point number by which to widen every character, excluding the space character, in a line of text. This value is used in proportional spacing. The value in this field is in 4.12 fractional notation: 4 bits of signed integer are followed by 12 bits of fraction. This value is multiplied by the value in the txSize field before it is used. By default, this field contains the value 0.
pnLocHFrac
The fractional horizontal pen position used when drawing text. The value in this field represents the low word of a Fixed number; in decimal, its initial value is 0.5.
portRect
The port rectangle that defines a subset of the pixel map to be used for drawing.All drawing done by the application occurs inside the port rectangle. (In a window's graphics port, the port rectangle is also called the content region .) The port rectangle uses the local coordinate system defined by the boundary rectangle in the portPixMap field of the PixMap record. The upper-left corner (which for a window is called the window origin ) of the port rectangle usually has a vertical coordinate of 0 and a horizontal coordinate of 0, although you can use the SetOrigin procedure (described in the chapter "Basic QuickDraw") to change the coordinates of the window origin. The port rectangle usually falls within the boundary rectangle, but it's not required to do so.
visRgn
The region of the graphics port that's actually visible on the screen--that is, the part of the window that's not covered by other windows. By default, the visible region is equivalent to the port rectangle. The visible region has no effect on images that aren't displayed on the screen.
clipRgn
The graphics port's clipping region, an arbitrary region that you can use to limit drawing to any region within the port rectangle. The default clipping region is set arbitrarily large; using the ClipRect procedure (described in the chapter "Basic QuickDraw"), you have full control over its setting. Unlike the visible region, the clipping region affects the image even if it isn't displayed on the screen.
bkPixPat
A handle to a PixPat record (described on PixPat ) that describes the background pixel pattern. Procedures such as ScrollRect (described in the chapter "Basic QuickDraw") and EraseRect (described in the chapter "QuickDraw Drawing") use this pattern for filling scrolled or erased areas. Your application can use the BackPixPat procedure (described on BackPixPat ) to change the background pixel pattern.
rgbFgColor
An RGBColor record (described on RGBColor ) that contains the requested foreground color. By default, the foreground color is black, but you can use the RGBForeColor procedure (described on RGBForeColor ) to change the foreground color.
rgbBkColor
An RGBColor record that contains the requested background color. By default, the background color is white, but you can use the RGBBackColor procedure (described on RGBBackColor ) to change the background color.
pnLoc
The point where QuickDraw will begin drawing the next line, shape, or character. It can be anywhere on the coordinate plane; there are no restrictions on the movement or placement of the pen. The location of the graphics pen is a point in the graphics port's coordinate system, not a pixel in a pixel image. The upper-left corner of the pen is at the pen location; the graphics pen hangs below and to the right of this point. The graphics pen is described in detail in the chapter "QuickDraw Drawing."
pnSize
The vertical height and horizontal width of the graphics pen. The default size is a 1-by-1 pixel square; the vertical height and horizontal width can range from 0 by 0 to 32,767 by 32,767. If either the pen width or the pen height is 0, the pen does not draw. Heights or widths of less than 0 are undefined. You can use the PenSize procedure (described in the chapter "QuickDraw Drawing") to change the value in this field.
pnMode
The pattern mode--that is, a Boolean operation that determines the how Color QuickDraw transfers the pen pattern to the pixel map during drawing operations. When the graphics pen draws into a pixel map, Color QuickDraw first determines what pixels in the pixel image are affected and finds their corresponding pixels in the pen pattern. Color QuickDraw then does a pixel-by-pixel comparison based on the pattern mode, which specifies one of eight Boolean transfer operations to perform. Color QuickDraw stores the resulting pixel in its proper place in the image. Pattern modes for a color graphics port are described in "Boolean Transfer Modes With Color Pixels," .
pnPixPat
A handle to a PixPat record (described on PixPat ) that describes a pixel pattern used like the ink in the graphics pen. Color QuickDraw uses the pixel pattern defined in the PixPat record when you use the Line and LineTo procedures to draw lines with the pen, framing procedures such as FrameRect to draw shape outlines with the pen, and painting procedures such as PaintRect to paint shapes with the pen.
fillPixPat
A handle to a PixPat record (described on PixPat ) that describes the pixel pattern that's used when you call a procedure such as FillRect to fill an area. Notice that this is not in the same location as the fillPat field in a GrafPort record.
pnVis
The graphics pen's visibility--that is, whether it draws on the screen. The graphics pen is described in detail in the chapter "QuickDraw Drawing."
txFont
A font number that identifies the font to be used in the graphics port. The font number 0 represents the system font. (A font is defined as a collection of images that represent the individual characters of the font.) Fonts are described in detail in Inside Macintosh: Text .
txFace
The character style of the text, with values from the set defined by the Style data type, which includes such styles as bold, italic, and shaded. You can apply stylistic variations either alone or in combination. Character styles are described in detail in Inside Macintosh: Text .
txMode
One of three Boolean source modes that determines the way characters are placed in the bit image. This mode functions much like a pattern mode specified in the pnMode field: when drawing a character, Color QuickDraw determines which pixels in the image are affected, does a pixel-by-pixel comparison based on the mode, and stores the resulting pixels in the image. Only three source modes-- srcOr , srcXor , and srcBic --should be used for drawing text. See the chapter "QuickDraw Text" in Inside Macintosh: Text for more information about QuickDraw's text-handling capabilities.
txSize
The text size in pixels. The Font Manager uses this information to provide the bitmaps for text drawing. (The Font Manager is described in detail in the chapter "Font Manager" in Inside Macintosh: Text .) The value in this field can be represented by point size ¥ device resolution / 72 dpi where point is a typographical term meaning approximately 1/72 inch.
spExtra
A fixed-point number equal to the average number of pixels by which each space character should be widened to fill out the line. The spExtra field is useful when a line of characters is to be aligned with both the left and the right margin (sometimes called full justification ).
fgColor
The pixel value of the foreground color supplied by the Color Manager. This is the best available approximation in the CLUT to the color specified in the rgbFgColor field.
bkColor
The pixel value of the background color supplied by the Color Manager. This is the best available approximation in the CLUT to the color specified in the rgbBkColor field.
colrBit
Reserved.
patStretch
A value used during output to a printer to expand patterns if necessary. Your application should not change this value.
picSave
The state of the picture definition. If no picture is open, this field contains NIL ; otherwise it contains a handle to information related to the picture definition. Your application shouldn't be concerned about exactly what information the handle leads to; you may, however, save the current value of this field, set the field to NIL to disable the picture definition, and later restore it to the saved value to resume defining the picture. Pictures are described in the chapter "Pictures" in this book.
rgnSave
The state of the region definition. If no region is open, this field contains NIL ; otherwise it contains a handle to information related to the region definition. Your application shouldn't be concerned about exactly what information the handle leads to; you may, however, save the current value of this field, set the field to NIL to disable the region definition, and later restore it to the saved value to resume defining the region.
polySave
The state of the polygon definition. If no polygon is open, this field contains NIL ; otherwise it contains a handle to information related to the polygon definition. Your application shouldn't be concerned about exactly what information the handle leads to; you may, however, save the current value of this field, set the field to NIL to disable the polygon definition, and later restore it to the saved value to resume defining the polygon.
grafProc s
An optional pointer to a CQDProcs record (described on CQDProcs ) that your application can store into if you want to customize Color QuickDraw drawing routines or use Color QuickDraw in other advanced, highly specialized ways.

All Color QuickDraw operations refer to a graphics port by a pointer defined by the data type CGrafPtr . (For historical reasons, a graphics port is one of the few objects in the Macintosh system software that's referred to by a pointer rather than a handle.) All Window Manager routines that accept a window pointer also accept a pointer to a color graphics port.

Your application should never need to directly change the fields of a CGrafPort record. If you find it absolutely necessary for your application to so, immediately use the PortChanged procedure to notify Color QuickDraw that your application has changed the CGrafPort record. The PortChanged procedure is described on PortChanged .

RGBColor

You usually specify a color to Color QuickDraw by creating an RGBColor record in which you assign the red, green, and blue values of the color. For example, when you want to set the foreground color for drawing, you create an RGBColor record that defines the foreground color you desire; then you pass that record as a parameter to the RGBForeColor procedure.

In an RGBColor record, three 16-bit unsigned integers give the intensity values for the three additive primary colors.

TYPE RGBColor=
RECORD
    red:       Integer;        {redcomponent}
    green:      Integer;        {greencomponent}
    blue:       Integer;        {bluecomponent}
END;
red
An unsigned integer specifying the red value of the color.
green
An unsigned integer specifying the green value of the color.
blue
An unsigned integer specifying the blue value of the color.

ColorSpec

When creating a PixMap record (described on PixMap ) for an indexed device, Color QuickDraw creates a ColorTable record that defines the best colors available for the pixel image on that graphics device. The Color Manager also stores a ColorTable record for the currently available colors in the graphics device's CLUT.

One of the fields in a ColorTable record requires a value of type cSpecArray , which is defined as an array of ColorSpec records. Typically, your application never needs to create ColorTable records or ColorSpec records. For completeness, the data structure of type ColorSpec is shown here, and the data structure of type ColorTable is shown next.

TYPE
cSpecArray: ARRAY[0..0] Of ColorSpec;
ColorSpec =
RECORD
    value:      Integer;        {index or other value}
    rgb:        RGBColor;       {true color}
END;
value
The pixel value assigned by Color QuickDraw for the color specified in the rgb field of this record. Color QuickDraw assigns a pixel value based on the capabilities of the user's screen. For indexed devices, the pixel value is an index number assigned by the Color Manager to the closest color available on the indexed device; for direct devices, this value expresses the best available red, green, and blue values for the color on the direct device.
rgb
An RGBColor record (described in the previous section) that fully specifies the color whose approximation Color QuickDraw specifies in the value field.

ColorTable

When creating a PixMap record (described on PixMap ) for a particular graphics device, Color QuickDraw creates a ColorTable record that defines the best colors available for the pixel image on that particular graphics device. The Color Manager also creates a ColorTable record of all available colors for use by the CLUT on indexed devices.

Typically, your application needs to create ColorTable records only if it uses the Palette Manager, as described in the chapter "Palette Manager" in Inside Macintosh: Advanced Color Imaging. The data structure of type ColorTable is shown here.

TYPE CTabHandle         =^CTabPtr;
CTabPtr                 =^ColorTable;
ColorTable              =
RECORD
    ctSeed:     LongInt;        {unique identifier from table}
    ctFlags:    Integer;        {flags describing the value in the }
                                { ctTable field; clear for a pixel map}
    ctSize:    Integer;        {numberofentriesinthe next field }
                                { minus 1}
    ctTable:    cSpecArray;     {an array of ColorSpec records}
END;
ctSeed
Identifies a particular instance of a color table. The Color Manager uses the ctSeed value to compare an indexed device's color table with its associated inverse table (a table it uses for fast color lookup). When the color table for a graphics device has been changed, the Color Manager needs to rebuild the inverse table. See the chapter "Color Manager" in Inside Macintosh: Advanced Color Imaging for more information on inverse tables.
ctFlags
Flags that distinguish pixel map color tables from color tables in GDevice records (which are described in the chapter "Graphics Devices" in this book).
ctSize
One less than the number of entries in the table.
ctTable
An array of ColorSpec entries, each containing a pixel value and a color specified by an RGBColor record, as described in the previous section.

Your application should never need to directly change the fields of a ColorTable record. If you find it absolutely necessary for your application to so, immediately use the CTabChanged procedure to notify Color QuickDraw that your application has changed the ColorTable record. The CTabChanged procedure is described on CTabChanged .

MatchRec

As described in "Application-Defined Routine" , you can customize the SeedCFill and CalcCMask procedures by writing your own color search functions and pointing to them in the matchProc parameters for these procedures.

When SeedCFill or CalcCMask calls your color search function, the GDRefCon field of the current GDevice record (described in the chapter "Graphics Devices") contains a pointer to a MatchRec record. This record contains the RGB value of the seed pixel or seed color for which your color search function should search. This record has the following structure:

MatchRec =
RECORD
    red:            Integer;    {red component of seed}
    green:          Integer;    {green component of seed}
    blue:           Integer;    {blue component of seed}
    matchData:      LongInt;    {value in matchData parameter of }
                                { SeedCFill or CalcCMask}
END;
red
Red value of the seed.
green
Green value of the seed.
blue
Blue value of the seed.
matchData
The value passed in the matchData parameter of the SeedCFill or CalcCMask procedure.

PixPat

Your application typically does not create PixPat records. Although you can create such records in your program code, it is usually easier to create pixel patterns using the pixel pattern resource, which is described on The Pixel Pattern Resource .

A PixPat record is defined as follows:

TYPE PixPatHandle       = ^PixPatPtr;
PixPatPtr               = ^PixPat;
PixPat                  =
RECORD
    patType :       Integer;            {pattern type}
    patMap:         PixMapHandle;       {pattern characteristics}
    patData:        Handle;             {pixel image defining pattern}
    patXData:       Handle;             {expanded pixel image}
    patXValid:      Integer;            {flags for expanded pattern data}
    patXMap:        Handle;             {handle to expanded pattern data}
    pat1Data:       Pattern;            {a bit pattern for a GrafPort }
                                        { record}
END;
patType
The pattern's type. The value 0 specifies a basic QuickDraw bit pattern, the value 1 specifies a full-color pixel pattern, and the value 2 specifies an RGB pattern. These pattern types are described in greater detail in the rest of this section.
patMap
A handle to a PixMap record (described on PixMap ) that describes the pattern's pixel image. The PixMap record can contain indexed or direct pixels.
patData
A handle to the pattern's pixel image.
patXData
A handle to an expanded pixel image used internally by Color QuickDraw.
patXValid
A flag that, when set to -1, invalidates the expanded data.
patXMap
Reserved for use by Color QuickDraw.
pat1Data
A bit pattern (described in the chapter "QuickDraw Drawing") to be used when this pattern is drawn into a GrafPort record (described in the chapter "Basic QuickDraw"). The NewPixPat function (described on NewPixPat ) sets this field to 50 percent gray.

When used for a color graphics port, the basic QuickDraw procedures PenPat and BackPat (described in the chapter "Basic QuickDraw") store pixel patterns in, respectively, the pnPixPat and bkPixPat fields of the CGrafPort record and set the patType field of the PixPat field to 0 to indicate that the PixPat record contains a bit pattern. Such patterns are limited to 8-by-8 pixel dimensions and, instead of being drawn in black and white, are always drawn using the colors specified in the CGrafPort record's rgbFgColor and rgbBkColor fields, respectively.

In a full-color pixel pattern, the patType field contains the value 1, and the pattern's dimensions, depth, resolution, set of colors, and other characteristics are defined by a PixMap record, referenced by the handle in the patMap field of the PixPat record. Full-color pixel patterns contain color tables that describe the colors they use. Generally such a color table contains one entry for each color used in the pattern. For instance, if your pattern has five colors, you would probably create a 4 bits per pixel pattern that uses pixel values 0-4, and a color table with five entries, numbered 0-4, that contain the RGB specifications for those pixel values.

However, if you don't specify a color table for a pixel value, Color QuickDraw assigns a color to that pixel value. The largest unassigned pixel value becomes the foreground color; the smallest unassigned pixel value is assigned the background color. Remaining unassigned pixel values are given colors that are evenly distributed between the foreground and background.

For instance, in the color table mentioned above, pixel values 5-15 are unused. Assume that the foreground color is black and the background color is white. Pixel value 15 is assigned the foreground color, black; pixel value 5 is assigned the background color, white; the nine pixel values between them are assigned evenly distributed shades of gray. If the PixMap record's color table is set to NIL , all pixel values are determined by blending the foreground and background colors.

Full-color pixel patterns are not limited to a fixed size: their height and width can be any power of 2, as specified by the height and width of the boundary rectangle for the PixMap record specified in the patMap field. A pattern 8 bits wide, which is the size of a bit pattern, has a row width of just 1 byte, contrary to the usual rule that the rowBytes field must be even. Read this pattern type into memory using the GetPixPat function (described on GetPixPat ), and set it using the PenPixPat or BackPixPat procedure (described on PenPixPat and BackPixPat , respectively).

The pixel map specified in the patMap field of the PixPat record defines the pattern's characteristics. The baseAddr field of the PixMap record for that pixel map is ignored. For a full-color pixel pattern, the actual pixel image defining the pattern is stored in the handle in the patData field of the PixPat record. The pattern's pixel depth need not match that of the pixel map into which it's transferred; the depth is adjusted automatically when the pattern is drawn. Color QuickDraw maintains a private copy of the pattern's pixel image, expanded to the current screen depth and aligned to the current graphics port, in the patXData field of the PixPat record.

In an RGB pixel pattern, the patType field contains the value 2. Using the MakeRGBPat procedure (described on MakeRGBPat ), your application can specify the exact color it wants to use. Color QuickDraw selects a pattern to approximate that color. In this way, your application can effectively increase the color resolution of the screen. RGB pixel patterns are particularly useful for dithering: mixing existing colors together to create the illusion of a third color that's unavailable on an indexed device. The MakeRGBPat procedure aids in this process by constructing a dithered pattern to approximate a given absolute color. An RGB pixel pattern can display 125 different patterns on a 4-bit screen, or 2197 different patterns on an 8-bit screen.

An RGB pixel pattern has an 8-by-8 pixel pattern that is 2 bits deep. For an RGB pixel pattern, the RGBColor record that you specify to the MakeRGBPat procedure defines the image; there is no image data.

Your application should never need to directly change the fields of a PixPat record. If you find it absolutely necessary for your application to so, immediately use the PixPatChanged procedure to notify Color QuickDraw that your application has changed the PixPat record. The PixPatChanged procedure is described on PixPatChanged .

CQDProcs

You need to use the CQDProcs record only if you customize one or more of QuickDraw's standard low-level drawing routines, which are described in the chapter "QuickDraw Drawing." You can use the SetStdCProcs procedure, described on SetStdCProcs , to create a CQDProcs record.

CQDProcsPtr     = ^CQDProcs
CQDProcs        =
RECORD
    textProc:           Ptr;    {text drawing}
    lineProc:           Ptr;    {line drawing}
    rectProc:           Ptr;    {rectangle drawing}
    rRectProc:          Ptr;    {roundRect drawing}
    ovalProc:           Ptr;    {oval drawing}
    arcProc:            Ptr;    {arc/wedge drawing}
    polyProc:           Ptr;    {polygon drawing}
    rgnProc:            Ptr;    {region drawing}
    bitsProc:           Ptr;    {bit transfer}
    commentProc:        Ptr;    {picture comment processing}
    txMeasProc:         Ptr;    {text width measurement}
    getPicProc:         Ptr;    {picture retrieval}
    putPicProc:         Ptr ;   {picture saving}
    opcodeProc:         Ptr;    {reserved for future use}
    newProc1:           Ptr;    {reserved for future use}
    newProc2:           Ptr;    {reserved for future use}
    newProc3:           Ptr;    {reserved for future use}
    newProc4:           Ptr;    {reserved for future use}
    newProc5:           Ptr;    {reserved for future use}
    newProc6:           Ptr;    {reserved for future use}
END;
textProc
A pointer to the low-level routine that draws text. The standard QuickDraw routine is the StdText procedure.
lineProc
A pointer to the low-level routine that draws lines. The standard QuickDraw routine is the StdLine procedure.
rectProc
A pointer to the low-level routine that draws rectangles. The standard QuickDraw routine is the StdRect procedure.
rRectProc
A pointer to the low-level routine that draws rounded rectangles. The standard QuickDraw routine is the StdRRect procedure.
ovalProc
A pointer to the low-level routine that draws ovals. The standard QuickDraw routine is the StdOval procedure.
arcProc
A pointer to the low-level routine that draws arcs. The standard QuickDraw routine is the StdArc procedure.
polyProc
A pointer to the low-level routine that draws polygons. The standard QuickDraw routine is the StdPoly procedure.
rgnProc
A pointer to the low-level routine that draws regions. The standard QuickDraw routine is the StdRgn procedure.
bitsProc
A pointer to the low-level routine that copies bitmaps. The standard QuickDraw routine is the StdBits procedure.
commentProc
A pointer to the low-level routine for processing a picture comment. The standard QuickDraw routine is the StdComment procedure.
txMeasProc
A pointer to the low-level routine for measuring text width. The standard QuickDraw routine is the StdTxMeas function.
getPicProc
A pointer to the low-level routine for retrieving information from the definition of a picture. The standard QuickDraw routine is the StdGetPic procedure.
putPicProc
A pointer to the low-level routine for saving information as the definition of a picture. The standard QuickDraw routine is the StdPutPic procedure.
opcodeProc
Reserved for future use.
newProc1
Reserved for future use.
newProc2
Reserved for future use.
newProc3
Reserved for future use.
newProc4
Reserved for future use.
newProc5
Reserved for future use.
newProc6
Reserved for future use.

GrafVars

The GrafVars record contains color information in addition to that in the CGrafPort record, of which it is logically a part; the information is used by Color QuickDraw and the Palette Manager.

TYPE GrafVars =
RECORD
    rgbOpColor:             RGBColor;       {color for addPin, subPin, and }
                                            { blend}
    rgbHiliteColor:         RGBColor;       {color for highlighting}
    pmFgColor:              Handle;         {palette handle for foreground }
                                            { color}
    pmFgIndex:              Integer;        {index value for foreground}
    pmBkColor:              Handle;         {palette handle for background }
                                            { color}
    pmBkIndex:              Integer;        {index value for background}
    pmFlags:                Integer;        {flags for Palette Manager}
END;
rgbOpColor
The color for the arithmetic transfer operations addPin , subPin , and blend .
rgbHiliteColor
The highlight color for this graphics port.
pmFgColor
A handle to the palette that contains the foreground color.
pmFgIndex
The index value into the palette for the foreground color.
pmBkColor
A handle to the palette that contains the background color.
pmBkIndex
The index value into the palette for the background color .
pmFlags
Flags private to the Palette Manager.

See the chapter "Palette Manager" in Inside Macintosh: Advanced Color Imaging for further information on how the Palette Manager handles colors in a color graphics port.


© 1997 Apple Computer, Inc.

Previous | Chapter Top | Chapter Contents | Next